﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using GoodsInvoicing.Presentions.Presenter;
using GoodsInvoicing.BLL.Service;
using GoodsInvoicing.Views.View;
using GoodsInvoicing.Model.UserRole;

namespace GoodsInvoicing.Presentions.PresenterImpl
{
    public class UserSaveFormPresenter : IUserSaveFormPresenter
    {
        private UserSaveFormPresenter()
        {
            throw new NotSupportedException("无接口的实现.");
        }

        public UserSaveFormPresenter(IUserSaveForm view, IGI_UserService userService)
        {
            this.view = view;
            this.userService = userService;
        }

        #region 属性
        private IUserSaveForm view;
        public IUserSaveForm View
        {
            get{ return view;}
        }

        private IGI_UserService userService;
        public IGI_UserService UserService
        {
            get { return userService; } 
        }
        #endregion 属性

        #region 方法
        /// <summary>
        /// 初始化视图
        /// </summary>
        public void InitializeView()
        {
            this.View.UserAddButtonClick += new EventHandler<EventArgs>(View_UserAddButtonClick);
            this.View.UserSaveButtonClick += new EventHandler<EventArgs>(View_UserSaveButtonClick);
        }
        #endregion


        private void View_UserAddButtonClick(object sender, EventArgs e)
        {
            GI_User user = new GI_User(this.View.UserName, this.View.LoginName, this.View.LoginPWD, this.View.Telephone);

            this.UserService.Save(user);
        }

        private void View_UserSaveButtonClick(object sender, EventArgs e) 
        {
            GI_User user = new GI_User(this.View.UserName, this.View.LoginName, this.View.LoginPWD, this.View.Telephone);
            user.UserID = this.View.UserID;

            this.UserService.Update(user);
        }
    }
}
